<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

// ------------------------------------------------------------------------

/**
 * Application
 *
 */
class Db_admin extends K9_Deploy_Controller
{
	/**
     * Constructor
     *
     * @access  public
     * @return  void
     */
	public function __construct()
	{
		parent::__construct();	
		$this->load->model('deploy/db_admin_model');
		$this->_check_permit();
	}
	
	// ------------------------------------------------------------------------
	
	/**
     * Default entrance
     *
     * @access  public
     * @param   int
     * @return  void
     */
	public function view()
	{
		$data['language'] = $this->language;
		$data['list'] = $this->db_admin_model->get_db_info();
		if ($this->session->userdata('uid'))
		{	
			$this->array = $this->uri->uri_to_assoc(4);
			$this->_template ( $this->language . '/db_admin', $data );
		}
		else
		{
			$this->load->view($this->language.'/login',$data);
		}
	}

	public function add()
	{
		$db_name = $this->input->post('db_name',TRUE);
		$db_flag = $this->input->post('db_flag',TRUE);
		$data['db_name'] = $db_name;
		$data['db_flag'] = $db_flag;
		if($db_flag=='2'){
			system("cd `pwd`/deploy_cn/lib && php add_db.php");
                        system("cd `pwd`/deploy_us/lib && php add_db.php");
			$this->_message("配置文件更新成功。");
		}
		if($db_name==''||$db_flag==''){
			$this->_message("db_name|db_flag都不能为空");
		}else{
			$ret = $this->db_admin_model->db_add($data);
			if($ret!='0'){
				$this->_message($db_name."已经存在!");
			}else{
				system("cd `pwd`/deploy_cn/lib && php add_db.php");
				system("cd `pwd`/deploy_us/lib && php add_db.php");
				$this->_message("新增数据库成功!");
			}
		}
	}

}
